using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Level1State
{
    public enum Level1StateType
    {
        Idle, UseNormalSkill
    }

    public abstract class Level1State : State<Level1StateType>
    {
        protected BossLevel1 level1;
        public Level1State(BossLevel1 level1)
        {
            this.level1 = level1;
        }
    }

    #region "Level1States"
    public class Idle : Level1State
    {
        public Idle(BossLevel1 level1)
            : base(level1) { }

        public override Level1StateType Type { get => Level1StateType.Idle; }

        public override void Enter(Level1StateType from)
        {
            level1.boss.Anim.Play(level1.boss.IdleAnimation);
        }

        public override void Exit(Level1StateType to)
        {
        }

        public override void FixedUpdate()
        {
            level1.attackTimer -= Time.deltaTime;
            if (level1.attackTimer <= 0f)
            {
                level1.stateManager.ChangeState(Level1StateType.UseNormalSkill);
            }
        }

        public override void Update()
        {
        }
    }

    public class UseNormalSkill : Level1State
    {
        public UseNormalSkill(BossLevel1 level1)
            : base(level1) { }
        public override Level1StateType Type { get => Level1StateType.UseNormalSkill; }

        public override void Enter(Level1StateType from)
        {
            RandomInvokeSkill();
            //InvokeSkill("AcidRainFall");
        }

        private void InvokeSkill(string name)
        {
            Boss boss = level1.boss;
            boss.StartCoroutine(boss.GetSkill(name,"level1").StartInvoke(boss));
        }

        private void RandomInvokeSkill()
        {
            Boss boss = level1.boss;
            int count = boss.GetSkillsCount("level1");
            int skillIndex = Random.Range(0, count);
            boss.StartCoroutine(boss.GetSkill(skillIndex,"level1")?.StartInvoke(boss));
        }

        public override void Exit(Level1StateType to)
        {
        }

        public override void FixedUpdate()
        {
        }

        public override void Update()
        {
        }
    }

#endregion
}